<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .base-input {
        display: flex;
      }
    </style>
  </head>
  <body>
    <!-- 
      baseInput 组件的实现

     -->

    <div id="app"></div>

    <script src="../lib/vue3.js"></script>
    <script>
      const Root = {
        template: `
          <div>
            <h1>Root</h1>

            <BaseInput label="姓名" placeholder="请输入姓名" @focus="onFocus" @blur="onBlur" />

            <BaseInput label="密码" type="password" placeholder="请输入密码" maxlength="2" />
          </div>
        `,

        methods: {
          onFocus() {
            console.log("onFocus");
          },

          onBlur() {
            console.log("onBlur");
          },
        },
      };

      const BaseInput = {
        inheritAttrs: false,

        props: {
          label: {
            type: String,
            required: true,
          },

          // type: {
          //   type: String,
          //   default: "text",
          // },

          // placeholder: {
          //   type: String,
          // },

          // maxlength: String,

          // readonly: Boolean,
        },

        template: `
          <div class="base-input">
            <div>{{label}}: </div>  
            <input 
              v-bind="$attrs" />
          </div>
        `,
      };

      // 创建应用实例
      const app = Vue.createApp(Root);

      // 创建全局组件
      app.component("BaseInput", BaseInput);

      // 挂载应用到挂载点
      app.mount("#app");
    </script>
  </body>
</html>
